package jmine.tec.web.wicket.component.command.button;

import static jmine.tec.web.wicket.pages.form.WebFormPagesMessages.LABEL_BUTTON_BACK;

import org.apache.wicket.Page;
import org.apache.wicket.markup.html.form.Button;

/**
 * {@link ButtonCommand} que representa um botão de "Voltar"
 * 
 * @author katsuo.ogawa
 * @date Sep 13, 2011
 */
public class BackCommand extends AbstractButtonCommand {

    private final BackCommandHandler handler;

    /**
     * Construtor.
     * 
     * @param handler {@link BackCommandHandler}
     */
    public BackCommand(BackCommandHandler handler) {
        this.handler = handler;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public Page execute() {
        return this.handler.back();
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public String getLabel() {
        return LABEL_BUTTON_BACK.create().getMessage();
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public Button createButtonComponent(String id) {
        Button buttonBack = super.createButtonComponent(id);
        buttonBack.setDefaultFormProcessing(false);
        return buttonBack;
    }
}
